import request from '@/utils/request.ts';
import type {LoginResult, LoginUserVO} from "@/types/system/auth.ts";

/**
 * 登录
 * @param username 用户名
 * @param password 密码
 * @returns token
 */
export function login(username: string, password: string) {
  return request<LoginResult>({
    url: '/auth/login',
    method: 'post',
    data: {
      username,
      password
    }
  });
}

/**
 * 登出
 * @returns 是否成功
 */
export function logout() {
  return request<boolean>({
    url: '/auth/logout',
    method: 'post'
  });
}

/**
 * 获取验证码
 * @returns 验证码信息
 */
export function getCaptcha() {
  return request<{
    captchaId: string;
    captchaImage: string;
  }>({
    url: '/auth/captcha',
    method: 'get'
  });
}

/**
 * 获取当前用户信息
 * @returns 用户信息
 */
export function getUserInfo() {
  return request<LoginUserVO>({
    url: '/users/info',
    method: 'get'
  });
}

/**
 * 刷新token
 * @returns 新的token
 */
export function refreshToken() {
  return request<{ token: string }>({
    url: '/auth/refresh',
    method: 'post'
  });
}
